﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
using System.Drawing;
using System.Collections.Specialized;

namespace gpuHough.DirectX
{
    class Options
    {
        public bool? AlphaBlendEnable { get; set; }
        public byte? BlendFactor { get; set; }
        public bool? TextureEnable { get; set; }
        public Effect Effect { get; set; }

        public void Apply(Device device, Options permanentOptions)
        {
            //set properties accessed externally
            if (this.Effect == null) this.Effect = permanentOptions.Effect ?? null;
            if (!this.TextureEnable.HasValue) this.TextureEnable = permanentOptions.TextureEnable ?? true;
            
            //set applicable properties to device
            set(device, this);
        }

        public void Reset(Device device, Options permanentOptions)
        {
            set(device, permanentOptions);
        }

        private void set(Device device, Options targetOptions)
        {
            if (this.AlphaBlendEnable.HasValue) device.RenderState.AlphaBlendEnable = targetOptions.AlphaBlendEnable ?? false;
            if (this.BlendFactor.HasValue)
            {
                var blendFactor = targetOptions.BlendFactor ?? 255;
                device.RenderState.BlendFactor = Color.FromArgb(blendFactor, blendFactor, blendFactor, blendFactor);
            }
        }
    }
}
